//我要用到的一些接口
import service from "./http.js";

//用户登录
export function UserLogin(data) {
  return service({
    url: "/v1/user/login",
    method: "POST",
    data,
  });
}

// 用户图书查询
export function getBookSearch(data) {
  return service({
    url: `/v1/user/books?pageNum=${data.pageNum}&pageSize=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

// 读者规则
export function getUserRule() {
  return service({
    url: "/v1/user/rules",
    method: "GET",
  });
}

// 个人信息
export function getUserMessage() {
  return service({
    url: "/v1/user",
    method: "GET",
  });
}

//修改用户密码
export function postPassword(data) {
  return service({
    url: "/postPassword",
    method: "POST",
    data,
  });
}

// 用户借阅信息查询
export function getBookBorrows(data) {
  return service({
    url: `/v1/user/borrows?pageNum=${data.pageNum}&pageSize=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

// 用户违规信息查询
export function getViolations(data) {
  return service({
    url: `/v1/user/violations?pageNum=${data.pageNum}&pageSize=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}
//公告查询
export function getNotices() {
  return service({
    url: "/v1/user/notices",
    method: "GET",
  });
}

// 用户评论查询
export function getComments() {
  return service({
    url: "/v1/user/comments",
    method: "GET",
  });
}

//发布评论
export function postComments(data) {
  return service({
    url: "/v1/user/comments",
    method: "POST",
    data,
  });
}

// 用户评论查询
export function getChat() {
  return service({
    url: "/v1/user/ai_list_information/1923",
    method: "GET",
  });
}

// 用户评论查询
export function postChat(data) {
  return service({
    url: "/v1/user/ai_intelligent",
    method: "POST",
    data,
  });
}

//---------------------------- ------------------------------------
//管理员登录
export function AdminLogin(data) {
  return service({
    url: "/v1/bookAdmin/login",
    method: "POST",
    data,
  });
}

//管理员借阅图书
export function BorrowBook(data) {
  return service({
    url: "/v1/bookAdmin/borrow_book",
    method: "POST",
    data,
  });
}

//管理员借阅报表
export function getBorrowReport(data) {
  return service({
    url: `/v1/bookAdmin/get_borrow_statement?pageNum=${data.pageNum}&size=${data.size}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
    data,
  });
}

//查询是否借出
export function getQueryBook(data) {
  return service({
    url: `/v1/bookAdmin/query_book?bookNumber=${data.bookNumber}`,
    method: "GET",
  });
}
//还书查询看是否预期
export function getReturn(data) {
  return service({
    url: `/v1/bookAdmin/query_expire?bookNumber=${data}`,
    method: "GET",
  });
}

//归还图书
export function ReturnBook(data) {
  return service({
    url: "/v1/bookAdmin/return_book",
    method: "POST",
    data,
  });
}

//管理员还书管理
export function getBookMessage(data) {
  return service({
    url: `/v1/bookAdmin/query_expire/${data}`,
    method: "GET",
  });
}

//管理员还书报表
export function getReturnReport(data) {
  return service({
    url: `/v1/bookAdmin/get_return_statement?pageNum=${data.pageNum}&size=${data.size}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//管理员公告列表获取
export function getNotice(data) {
  return service({
    url: `/v1/bookAdmin/get_notice_list?pageNum=${data.pageNum}&pageSize=${data.pageSize}`,
    method: "GET",
  });
}

//管理员添加公告
export function addNotices(data) {
  return service({
    url: "/v1/bookAdmin/add_notice",
    method: "POST",
    data,
  });
}

//管理员删除公告
export function removeNotice(data) {
  return service({
    url: `/v1/bookAdmin/delete_notice`,
    method: "POST",
    data,
  });
}

//管理员修改公告
export function alterNotice(data) {
  return service({
    url: `/v1/bookAdmin/update_notice`,
    method: "POST",
    data,
  });
}
//管理员获取指定公告
export function getOneNotice(data) {
  return service({
    url: `/v1/bookAdmin/get_notice?noticeId=${data}`,
    method: "GET",
  });
}

//------------------------------------------------------------------------
//超级管理员登录
export function SuperAdminLogin(data) {
  return service({
    url: "/v1/admin/login",
    method: "POST",
    data,
  });
}

//书籍列表获取
export function getBooksList(data) {
  return service({
    url: `/v1/admin/bookLists?pageNum=${data.pageNum}&size=${data.size}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//添加新书
export function addBook(data) {
  return service({
    url: "/v1/admin/books",
    method: "POST",
    data,
  });
}

//删除书籍
export function removeBook(data) {
  return service({
    url: `/v1/admin/books?bookId=${data}`,
    method: "DELETE",
  });
}

//改书
export function alterBook(data) {
  return service({
    url: `/v1/admin/books`,
    method: "PUT",
    data,
  });
}

//获取指定书籍
export function getOneBook(data) {
  return service({
    url: `/v1/admin/books?bookId=${data}`,
    method: "GET",
  });
}

//删除多个图书
export function delAllBook(data) {
  return service({
    url: `/v1/admin/allBooks`,
    method: "DELETE",
    data,
  });
}

//类型获取
export function getTypeList(data) {
  return service({
    url: `/v1/admin/bookTypeList?pageNum=${data.pageNum}&size=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//获取指定类型
export function getOneType(data) {
  return service({
    url: `/v1/admin/bookType?typeId=${data}`,
    method: "GET",
  });
}

//修改指定类型
export function postOneType(data) {
  return service({
    url: `/v1/admin/bookType`,
    method: "PUT",
    data,
  });
}

//删除指定类型
export function delOneType(data) {
  return service({
    url: `/v1/admin/bookType?typeId=${data}`,
    method: "DELETE",
  });
}
//增加类型
export function addType(data) {
  return service({
    url: `/v1/admin/bookType`,
    method: "POST",
    data,
  });
}

//获取借阅证列表
export function getBorrowList(data) {
  return service({
    url: `/v1/admin/libraryCardsList?pageNum=${data.pageNum}&size=${data.size}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//获取借阅规则
export function getBorrowRules() {
  return service({
    url: `/v1/admin/borrowAllRulesList`,
    method: "GET",
  });
}

//添加借阅证
export function addBorrow(data) {
  return service({
    url: `/v1/admin/libraryCards`,
    method: "POST",
    data,
  });
}

//获取指定借阅证
export function getOneBorrow(data) {
  return service({
    url: `/v1/admin/libraryCards?userId=${data}`,
    method: "GET",
  });
}

//修改指定借阅证
export function postOneBorrow(data) {
  return service({
    url: `/v1/admin/libraryCards`,
    method: "PUT",
    data,
  });
}

//删除指定类型
export function delOneBorrow(data) {
  return service({
    url: `/v1/admin/libraryCards?userId=${data}`,
    method: "DELETE",
  });
}

//查询借阅信息
export function GetBorrowMessage(data) {
  return service({
    url: `/v1/admin/borrowsList?pageNum=${data.pageNum}&pageSize=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//获取规则列表
export function getRulesList(data) {
  return service({
    url: `/v1/admin/borrowRulesList?pageNum=${data.pageNum}&pageSize=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//添加规则
export function addaRule(data) {
  return service({
    url: `/v1/admin/borrowRules`,
    method: "POST",
    data,
  });
}

//获取指定规则
export function getOneRule(data) {
  return service({
    url: `/v1/admin/borrowRules?ruleId=${data}`,
    method: "GET",
  });
}

//修改指定规则
export function postOneRule(data) {
  return service({
    url: `/v1/admin/borrowRules`,
    method: "PUT",
    data,
  });
}

//删除指定规则
export function delOneRule(data) {
  return service({
    url: `/v1/admin/borrowRules?ruleId=${data}`,
    method: "DELETE",
  });
}

//获取管理员列表
export function getAdminList(data) {
  return service({
    url: `/v1/admin/bookAdminList?pageNum=${data.pageNum}&size=${data.pageSize}&query=${data.query}&condition=${data.condition}`,
    method: "GET",
  });
}

//添加管理员
export function addAdmin(data) {
  return service({
    url: `/v1/admin/bookAdmin`,
    method: "POST",
    data,
  });
}

//获取指定管理员
export function getOneAdmin(data) {
  return service({
    url: `/v1/admin/bookAdmin?adminId=${data}`,
    method: "GET",
  });
}

//修改指定管理员
export function postOneAdmin(data) {
  return service({
    url: `/v1/admin/bookAdmin`,
    method: "PUT",
    data,
  });
}

//删除指定管理员
export function delOneAdmin(data) {
  return service({
    url: `/v1/admin/bookAdmin?adminId=${data}`,
    method: "DELETE",
  });
}

//获取简单图书列表
export function getSimpleBookTypeLis() {
  return service({
    url: `/v1/admin/simpleBookTypeList`,
    method: "GET",
  });
}

//获取最近28天借阅信息
export function getBorrowData() {
  return service({
    url: `/v1/admin/borrowData`,
    method: "GET",
  });
}
//获取所有借书分析
export function getBorrowTypeData() {
  return service({
    url: `/v1/admin/borrowTypeData`,
    method: "GET",
  });
}

// //导出全部图书
export async function ExportAllBook(data) {
  const res = await service({
    url: `/v1/user/book/export?query=${data.query}&condition=${data.condition}`,
    method: "GET",
    responseType: "blob",
    // headers: {
    // Accept: "application/zip",
    // },
  });

  console.log(res);
  // 创建一个 URL
  const url = window.URL.createObjectURL(res);

  // 创建下载链接
  const a = document.createElement("a");
  a.href = url;
  a.download = "book_data.zip"; // 设置下载的文件名

  // 触发下载
  document.body.appendChild(a);
  a.click();

  // 清理工作
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
}
